<%@ page contentType="text/html; charset=UTF-8" language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML>
<html>
<head>
<title>三尺山教育信息咨询有限公司后台管理系统</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript" src="../../jslib/jquery-easyui-1.3.1/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="../../jslib/jquery-easyui-1.3.1/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../../jslib/jquery-easyui-1.3.1/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="../../jslib/tools.js"></script>
<link rel="stylesheet" href="../../jslib/jquery-easyui-1.3.1/themes/default/easyui.css" type="text/css"></link>
<link rel="stylesheet" href="../../jslib/jquery-easyui-1.3.1/themes/icon.css" type="text/css"></link>
<style type="text/css">
.myBut {
	border: 1px solid #00FF99;
	background-color: #CCE8CF;
}
</style>
<script type="text/javascript" charset="utf-8">
	$(function() {
		$('#moduls_user_datagrid').datagrid({
			url : '${pageContext.request.contextPath}/newsAction!getList.action',
			fit : true,
			pagination : true,
			border : false,
			checkOnSelect : false,
			pagination : true,
			rownumbers : true,
			pageList : [ 25, 50, 75, 100 ],
			selectOnCheck : false,
			idField : 'userId',
			nowrap : false,
			columns : [ [ {
				title : 'ID',
				field : 'id',
				width : 50,
				hidden : true
			}, {
				title : '新闻标题',
				field : 'name',
				width : 350
			}, {
				title : '新闻类型',
				field : 'type',
				width : 100,
				formatter : function(value, row, index) {
					return row.typeName;
				}
			}, {
				title : '发布日期',
				field : 'addDate',
				width : 100
			}, {
				title : '通过审核',
				field : 'ckbIsPass',
				width : 100,
				formatter : function(value, row, index) {
					var str = 'cancel.png';
					if (value == 1) {
						str = 'ok.png';
					}
					return '<img alt="" src="${pageContext.request.contextPath}/jslib/jquery-easyui-1.3.1/themes/icons/'+str+'">';
				}
			}, {
				title : '头条推荐',
				field : 'ckbtop',
				width : 100,
				formatter : function(value, row, index) {
					var str = 'cancel.png';
					if (value == 1) {
						str = 'ok.png';
					}
					return '<img alt="" src="${pageContext.request.contextPath}/jslib/jquery-easyui-1.3.1/themes/icons/'+str+'">';
				}
			}, {
				title : '热点推荐',
				field : 'cknishot',
				width : 100,
				formatter : function(value, row, index) {
					var str = 'cancel.png';
					if (value == 1) {
						str = 'ok.png';
					}
					return '<img alt="" src="${pageContext.request.contextPath}/jslib/jquery-easyui-1.3.1/themes/icons/'+str+'">';
				}
			}, {
				title : '查看页面',
				field : 'aaa',
				width : 100,
				formatter : function(value, row, index) {
					return '<input type="button" onclick="queryPage(' + row.id + ')" class="myBut" value="查看页面" />';
				}
			}, {
				title : '图片管理',
				field : 'zzzz',
				width : 100,
				formatter : function(value, row, index) {
					return '<input type="button" onclick="imgManager(' + row.id + ',\''+row.filename+'\',\''+row.falg+'\')" class="myBut" value="图片管理" />';
				}
			}, {
				field : 'action1',
				title : '操作',
				width : 80,
				formatter : function(value, row, index) {
					return '<a href="${pageContext.request.contextPath}/Admin/NewManager/NewModify.jsp?id=' + row.id + '"><img alt="修改" src="${pageContext.request.contextPath}/jslib/jquery-easyui-1.3.1/themes/icons/book_edit.png"></a>&nbsp;&nbsp;<a href="javascript:void(0)" onclick="del(' + row.id + ')" ><img alt="删除" src="${pageContext.request.contextPath}/jslib/jquery-easyui-1.3.1/themes/icons/icon_trash.gif"></a>';
				}
			} ] ],
			toolbar : '#moduls_user_datagrid_toolbar'
		});
	});

	function addPage() {
		window.location.href = "NewEdit.jsp";
	}

	function queryPage(id) {
		window.open('${pageContext.request.contextPath}/news/news.jsp?id=' + id);
	}

	function del(id) {
		$.messager.confirm('确认', '您是否要删除？', function(r) {
			if (r) {
				$.ajax({
					url : '${pageContext.request.contextPath}/newsAction!delete.action',
					data : {
						id : id
					},
					dataType : 'json',
					success : function(result) {
						if (result.success) {
							$('#moduls_user_datagrid').datagrid('load');
						}
						$.messager.show({
							title : '提示',
							msg : result.msg
						});
					}
				});
			}
		});
	}
	function modify(id) {
		new_id = id;
		addPage('moduls/modifyNew.jsp');
	}
</script>
</head>
<body>
	<table id="moduls_user_datagrid"></table>
	<div id="moduls_user_datagrid_toolbar">
		<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="addPage();">增加新闻</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
		
		<input id="addDate" type="text" class="easyui-datebox"></input>
		<div id="moduls_user_datagrid_toolbar_group" style="width:120px; height: 300px; overflow: auto;">
			<div data-options="name:'0',iconCls:'icon-group'">请选择类型</div>
			<div id="menuId" class="menu-sep"></div>
		</div>
		<input id="moduls_user_datagrid_toolbar_user"></input>
		<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="cleara();">清空</a>
	</div>
	<div id="imgManager"><table id="moduls_img_datagrid"></table></div>
	<div id="modifyNewsImgDiv">
		<br/>
		<form action="" id="addNewsImgFormId" method="post" enctype="multipart/form-data">
		<table>
			<tr>
				<th style="font-weight: normal;width: 100px;">图片描述：</th>
				<td><input type="text" name="des" /></td>
			</tr>
			<tr>
				<th style="font-weight: normal;width: 100px;">图片文件：</th>
				<td><input type="file" name="img" /></td>
			</tr>
		</table>
		</form>
	</div>
	<div id="odModifyNewsImgDiv">
		<br/>
		<form action="" id="doAddNewsImgFormId" method="post" enctype="multipart/form-data">
		<input type="hidden" name="id">
		<input type="hidden" name="di">
		<input type="hidden" name="filename">
		<input type="hidden" name="falg">
		<input type="hidden" name="imgCount">
		<table>
			<tr>
				<th style="font-weight: normal;width: 100px;">图片描述：</th>
				<td><input type="text" name="fileDes" /></td>
			</tr>
			<tr>
				<th style="font-weight: normal;width: 100px;">图片文件：</th>
				<td><input type="file" name="img" /></td>
			</tr>
			<tr>
				<th style="font-weight: normal;width: 100px;"></th>
				<td>不修改图片可以不上传图片</td>
			</tr>
		</table>
		</form>
	</div>
	<script type="text/javascript" charset="UTF-8">
		var cateName = "";
		var groups = undefined;
		function cleara() {
			$('#moduls_user_datagrid_toolbar_user').searchbox('setValue', '');
			$('#moduls_user_datagrid_toolbar_user').searchbox('selectName', '0');
			$('#addDate').combo('clear');
			cateName = "";
			$('#moduls_user_datagrid').datagrid('load');
		}
	
	
		$(function() {
			$('#moduls_user_datagrid_toolbar_user').searchbox({
				searcher : function(username, groupId) {
					$('#moduls_user_datagrid').datagrid('load', {
						typeName : groupId==0?'':groups[groupId-1].name,
						name : username,
						addDate : $('#addDate').combo('getText'),
					});
				},
				menu : '#moduls_user_datagrid_toolbar_group',
				prompt : '请输入新闻标题'
			});
			$.ajax({
				type : 'POST',
				url : '${pageContext.request.contextPath}/newsAction!getCate.action',
				cache : false,
				dataType : 'JSON',
				success : function(group) {
					groups = group;
					for ( var i = 0; i < group.length; i++) {
						$('#moduls_user_datagrid_toolbar_group').menu('appendItem', {
							name : group[i].id,
							id : 'nameId'+group[i].id,
							text : group[i].name,
							iconCls : 'icon-group'
						});
					}
				}
			});
		});
	</script>
	
	<script type="text/javascript">
		var cId = "";
		var cFalg = "";
		var imgCount = 0;
		function imgManager(id, filename, falg) {
			cId = id;
			cFalg = falg;
			$('#imgManager').dialog({
				title : '新闻图片管理',
				width : 700,
				height : 500,
				closed : false,
				closable : false,
				modal : true,
				buttons : [ {
					text : '关闭',
					iconCls : 'icon-remove',
					handler : function() {
						$('#imgManager').dialog('close');
					}
				} ],
				onOpen : function() {
					$('#moduls_img_datagrid').datagrid({
						url : '${pageContext.request.contextPath}/newsAction!getImgByFalg.action?falg='+falg,
						fit : true,
						pagination : true,
						border : false,
						checkOnSelect : false,
						rownumbers : true,
						selectOnCheck : false,
						idField : 'id',
						nowrap : false,
						columns : [ [ {
							title : 'ID',
							field : 'id',
							width : 50,
							hidden : true
						}, {
							title : '图片描述',
							field : 'des',
							width : 280
						}, {
							title : '图片名称',
							field : 'name',
							width : 280
						}, {
							field : 'action1',
							title : '操作',
							width : 80,
							formatter : function(value, row, index) {
								imgCount = imgCount+1;
								return '<img onclick="modifyNewsImg(' + row.id + ',\''+row.des+'\', \''+row.name+'\',\''+row.falg+'\',\''+imgCount+'\')" title="修改" alt="修改" src="${pageContext.request.contextPath}/jslib/jquery-easyui-1.3.1/themes/icons/book_edit.png">&nbsp;&nbsp;<img onclick="delNewsImg(' + row.id + ',\''+row.des+'\', \''+row.name+'\',\''+row.falg+'\',\''+imgCount+'\')" title="删除图片" alt="删除图片" src="${pageContext.request.contextPath}/jslib/jquery-easyui-1.3.1/themes/icons/edit_remove.png">&nbsp;&nbsp;<a href="javascript:void(0)" onclick="queryImg(\'' + row.name + '\')" ><img title="查看图片" src="${pageContext.request.contextPath}/jslib/jquery-easyui-1.3.1/themes/icons/zoom.png"></a>';
							}
						} ] ],
						toolbar : [ {
							text : '增加图片',
							iconCls : 'icon-add',
							handler : function() {
								addNewsImg();
							}
						} ],
						onBeforeLoad : function(data) {
							imgCount = 0;
						}
					});
				}
			});
		}
		
		function modifyNewsImg(id, des, name, falg,count) {
			$('#odModifyNewsImgDiv').dialog({
				title : '修改新闻图片',
				width : 400,
				height : 200,
				closed : false,
				closable : false,
				modal : true,
				buttons : [ {
					text : '保存',
					iconCls : 'icon-edit',
					handler : function() {
						$('#doAddNewsImgFormId').form('submit', {
							url : '${pageContext.request.contextPath}/newsAction!updateNewsImg.action',
							success : function(result) {
								try {
									var r = $.parseJSON(result);
									if (r.success) {
										$('#odModifyNewsImgDiv').dialog('close');
										$('#moduls_img_datagrid').propertygrid('load');
									}
									$.messager.show({
										title : '提示',
										msg : r.msg
									});
								} catch (e) {
									$.messager.alert('提示', result);
								}
							}
						});
					}
				}, {
					text : '取消',
					iconCls : 'icon-edit',
					handler : function() {
						$('#odModifyNewsImgDiv').dialog('close');
					}
				} ]
			});
			
			$("#doAddNewsImgFormId input[name=id]").val(id);
			$("#doAddNewsImgFormId input[name=di]").val(cId);
			$("#doAddNewsImgFormId input[name=fileDes]").val(des);
			$("#doAddNewsImgFormId input[name=filename]").val(name);
			$("#doAddNewsImgFormId input[name=falg]").val(falg);
			$("#doAddNewsImgFormId input[name=imgCount]").val(count);
		}
		function delNewsImg(id, des, name, falg, count) {
			$.messager.confirm('确认', '您是否要删除？', function(r) {
				if (r) {
					$.ajax({
						url : '${pageContext.request.contextPath}/newsAction!delNewsImg.action',
						data : {
							id : id,
							di : cId,
							imgCount : count,
							falg : falg
						},
						dataType : 'json',
						success : function(result) {
							if (result.success) {
								$('#moduls_img_datagrid').datagrid('load');
							}
							$.messager.show({
								title : '提示',
								msg : result.msg
							});
						}
					});
				}
			});
		}
		
		function queryImg(img) {
			window.open('${pageContext.request.contextPath}/images/img/'+img);
		}
		
		function addNewsImg() {
			$('#modifyNewsImgDiv').dialog({
				title : '上传图片',
				width : 400,
				height : 200,
				closed : false,
				closable : false,
				modal : true,
				buttons : [ {
					text : '保存',
					iconCls : 'icon-save',
					handler : function() {
						$('#addNewsImgFormId').form('submit', {
							url : '${pageContext.request.contextPath}/newsAction!addNewsImg.action?id='+cId+'&imgCount='+imgCount+'&falg='+cFalg,
							success : function(result) {
								try {
									var r = $.parseJSON(result);
									if (r.success) {
										$('#modifyNewsImgDiv').dialog('close');
										$('#moduls_img_datagrid').propertygrid('load');
									}
									$.messager.show({
										title : '提示',
										msg : r.msg
									});
								} catch (e) {
									$.messager.alert('提示', result);
								}
							}
						});
					}
				}, {
					text : '取消',
					iconCls : 'icon-cancel',
					handler : function() {
						$('#modifyNewsImgDiv').dialog('close');
					}
				} ]
			});
		}
	</script>
</body>